<?php 
require_once 'lib/swift_required.php';

$email_address = $_POST["email_address"];

if ($email_address == '' or $email_address == null) {
	$email_address = $_GET["email_address"];
}

$type = $_POST["type"];

if ($type == '' or $type == null) {
	$type = $_GET["type"];
}

$email_address = "ncastro@xeliom.com";

$username = 'nicolazcastro@gmail.com';
$password = 'suhcyhvcahya';

$fileName = '/planillas/apartamento.xlsx';

$transporter = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587, 'ssl')
->setUsername($username)
->setPassword($password);

// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transporter);

// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array($username => 'Nicolas Castro'))
->setTo(array($email_address => 'A name'))
->setBody('Here is the message itself')
->attach(Swift_Attachment::fromPath($fileName)->setFilename('apartamento.xlsx'))
;

$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array($username => 'Nicolas Castro'))
->setTo(array($email_address => 'A name'))
->setBody('Here is the message itself')
;

try{
	$result = $mailer->send($message);
}catch(Exception $e){
	echo $e;
	die;
}


$data = array('status' => $status, 'email' => $email_address, 'message' => $result);

$json = json_encode($data);

echo $json;
?>